package atom.ui.components.input 
{
	import atom.ui.ComponentContainer;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author Jorge Braccini
	 */
	public class Button extends ComponentContainer {
		
		private var _tmpColor:uint;
		
		public function Button(init:Object = null) {
			super(init);
		}
		
		/////////////////////////////////////////
		// Public Methods ///////////////////////
		/////////////////////////////////////////
		
		override public function update():void {
			super.update();
			
			updateEnabled();
			updateLabel();
		}
		
		/////////////////////////////////////////
		// Protected Methods ////////////////////
		/////////////////////////////////////////
		
		protected function over():void {
			
		}
		
		protected function out():void {
			
		}
		
		override protected function initValues():void {
			super.initValues();
			
			init.enabled 	= true;
			init.bgColor	= 0xffffff;
			init.label		= "";
		}
		
		override protected function subscribe():void {
			super.subscribe();
			
			addEventListener(MouseEvent.CLICK, 		handleClick);
			addEventListener(MouseEvent.ROLL_OVER, 	handleRollOver);
			addEventListener(MouseEvent.ROLL_OUT, 	handleRollOut);
		}
		
		override protected function unsubscribe():void {
			super.unsubscribe();
			
			removeEventListener(MouseEvent.CLICK, 		handleClick);
			removeEventListener(MouseEvent.ROLL_OVER, 	handleRollOver);
			removeEventListener(MouseEvent.ROLL_OUT, 	handleRollOut);
		}
		
		override protected function draw():void {
			
		}
		
		/////////////////////////////////////////
		// Private Methods //////////////////////
		/////////////////////////////////////////
		
		private function handleRollOut(e:MouseEvent):void {
			over();
		}
		
		private function handleRollOver(e:MouseEvent):void {
			out();
		}
		
		private function handleClick(e:MouseEvent):void {
			
		}
		
		private function updateEnabled():void {
			buttonMode = enabled;
			alpha = enabled ? 1 : .5;
			
			enabled ? subscribe() : unsubscribe();
		}
		
		private function updateLabel():void {
			
		}
		
		/////////////////////////////////////////
		// Properties ///////////////////////////
		/////////////////////////////////////////
		
		public function get label():String { return init.label; }
		
		public function set label(value:String):void {
			init.label = value;
			update();
		}
		
		public function get bgColor():uint { return init.bgColor; }
		
		public function set bgColor(value:uint):void {
			init.bgColor = value;
			draw();
		}
		
		public function get enabled():Boolean { return init.enabled; }
		
		public function set enabled(value:Boolean):void {
			init.enabled = value;
			update();
		}
		
	}

}